//生产管理系统/数据趋势分析/填表
import React, { Component } from "react";
import { connect } from "dva";
import md5 from "blueimp-md5";
import PublicService from "../../../services/PublicService";
import { Form, Modal, message, Input } from "antd";
import moment from "moment";
import { passWd } from "../../../services/redmoe";
const { TextArea } = Input;

//form表单套件
const FormItem = Form.Item;

const ChangePwd = Form.create()(
    class extends React.Component {
        state = {
            visible: 1
        };

        handleSubmit = e => {
            console.log(3123);
            e.preventDefault();
            this.props.form.validateFields((err, values) => {
                if (err) {
                    return;
                }
                if (values.newPwd == values.oldPwd) {
                    message.warning("新密码不能与旧密码一致");
                    return;
                }

                console.log(name);
                setTimeout(() => {
                    console.log(PublicService.getCookie("userName"));
                    let data = {
                        userName: PublicService.getCookie("userName"),
                        newPassword: md5(values.newPwd),
                        oldPassword: md5(values.oldPwd)
                    };
                    passWd({ ...data }).then(data => {
                        console.log(data);
                        if (data.data.rc == 1) {
                            message.warning(data.data.err);
                        }
                        if (data.data.rc == 0) {
                            message.success("修改成功");
                            this.setState({
                                visible: 0
                            });
                        }
                    });
                }, 500);
            });
        };
        render() {
            const { getFieldDecorator, setFieldsValue } = this.props.form;

            const { visible, onCancel, onCreate, form, text } = this.props;

            return (
                <Modal
                    destroyOnClose={true}
                    visible={visible}
                    title="修改密码"
                    okText="保存"
                    cancelText="关闭"
                    onCancel={onCancel}
                    onOk={this.handleSubmit}
                >
                    <Form layout="inline">
                        <FormItem label="旧密码">
                            {getFieldDecorator("oldPwd", {
                                validateTrigger: ["onBlur", "onChange"],
                                rules: [
                                    { max: 8, message: "最多输入8个字" },
                                    { required: true, message: "必填" }
                                ]
                            })(
                                <Input type="textarea" style={{ width: 300 }} />
                            )}
                        </FormItem>
                        <FormItem label="新密码">
                            {getFieldDecorator("newPwd", {
                                validateTrigger: ["onBlur", "onChange"],
                                rules: [
                                    { max: 8, message: "最多输入8个字" },
                                    { required: true, message: "必填" }
                                ]
                            })(
                                <Input type="textarea" style={{ width: 300 }} />
                            )}
                        </FormItem>
                    </Form>
                </Modal>
            );
        }
    }
);

export default connect()(ChangePwd);
